package cn.bdqn.smbms.util;

import cn.bdqn.smbms.entity.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class SysInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        User userSession = (User)session.getAttribute("userSession");
        if(userSession!=null){
            return true;
        }else{
            response.sendRedirect(request.getContextPath()+"/index.jsp");
            return false;
        }
    }
}
